<style>
    .show{display: inherit}
    .hide{display: none}
    table tr td,table tr th{width: 5%}
    .layui-btn{margin-right: 10px}

    .layui-table-cell {overflow-x: hidden;overflow: inherit; }/*
    .layui-table-box {
        overflow: inherit;
    }
    .layui-table-body {
        overflow: inherit;
    }*/


</style>
<div class="fixed-bar" style="clear:both;">
    <form class="layui-form layui-form-pane fixed-bar-form" action="{:url('',['status' => $status])}" method="get" id="hisi-table-search">
        <div class="layui-form-item">
            <div class="layui-inline removeStat">
                <label class="layui-form-label">订单号</label>
                <div class="layui-input-inline">
                    <input type="text" name="client_ordernum" lay-verify="" placeholder="输入订单号" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label ">发起日期</label>
                <div class="layui-input-inline">
                    <input type="text" name="create_date_range" readonly="" id="create_date_range" lay-verify="" placeholder="选择创建日期" class="layui-input">
                </div>
            </div>
<!--            <div class="layui-inline">-->
<!--                <label class="layui-form-label ">回料日期</label>-->
<!--                <div class="layui-input-inline">-->
<!--                    <input type="text" name="create_date_range" readonly="" id="create_date_range2" lay-verify="" placeholder="选择创建日期" class="layui-input">-->
<!--                </div>-->
<!--            </div>-->
            <div class="layui-inline removeStat">
                <label class="layui-form-label">所属工厂</label>
                <div class="layui-input-inline">
                    {:Form::select('factory_id', '', $factoryKV, '', '')}
                </div>
            </div>
            <div class="layui-inline removeStat">
                <label class="layui-form-label">供应商</label>
                <div class="layui-input-inline">
                    <input type="text" name="supplier" lay-verify="" placeholder="输入供应商" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">发起人</label>
                <div class="layui-input-inline">
                    <input type="text" name="adminid_create_name" lay-verify="" placeholder="输入发起人" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">退料原因</label>
                <div class="layui-input-inline">
                    <input type="text" name="reason" lay-verify="" placeholder="输入退料原因" class="layui-input">
                </div>
            </div>
            <div class="layui-inline removeStat">
                <label class="layui-form-label">入库类型</label>
                <div class="layui-input-inline">
<!--                    {:Form::select('factory_id', '', [0=>'全部',1=>'余料入库',2=>'备料入库',3=>'常规面料入库'], '', '')}-->
                    {:Form::select('stock_m_type', '', $stock_m_type_super, '', '')}
                </div>
            </div>
            <div class="layui-inline">
                <button type="submit" id="seacher" class="layui-btn" lay-submit="" lay-filter="demo1">搜索</button>
            </div>
        </div>
    </form>
</div>
<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief" style="clear:both;">
    <ul class="layui-tab-title" id="vue_tab_content">
        <li class="layui-this"><a onclick="statCli(1)" href="#">待入库</a></li>
        <li><a onclick="statCli(2)" href="#">已完成</a></li>
    </ul>
    <div class="layui-tab-content">
        <table id="dataTable" lay-filter="demoEvent"></table>
    </div>
</div>



{include file="system@block/layui" /}

<script type="text/html" title="操作按钮模板" id="buttonTpl">
    <a href="{:url('stockActionDetail')}?batch_number={{d.batch_number}}" class="hisi-iframe blue bill-list-a stockActionDetail" hisi-data="{width: '70%', height: '77%'}" title="入库执行">入库执行</a>
    <a href="{:url('stockActionDetailSelect')}?batch_number={{d.batch_number}}&type=select" class="hisi-iframe blue bill-list-a stockActionDetailSelect" hisi-data="{width: '70%', height: '70%'}" title="查看明细">查看明细</a>
</script>
<script type="text/html" id="toolbar">
    <div class="layui-btn-group fl">
<!--        <a href="{:url('addStockOrder')}" class="layui-btn layui-btn-primary layui-btn-sm layui-icon layui-icon-add-circle-fine hisi-iframe addStockOrder" hisi-data="{width: '70%', height: '70%'}" title="新增余料入库单">&nbsp;新增余料入库单</a>-->
        <a data-href="{:url('stockActionDoCheckInCallBack')}" class=" layui-btn layui-btn-primary layui-btn-sm j-page-btns confirm layui-icon stockActionReturn" title="返回重置">返回重置</a>
    </div>
</script>
<script type="text/html" id="picTpl">
    <span class="lay-pic-container" src="{{ d.pic }}">
		<img src="{{ d.ori_pic }}" class="lay-pic">
	</span>
</script>
<script type="text/html" id="nameTpl">
    {{#  layui.each(d.detail, function(kkk, vvv){ }}
    {{layui.tool.formatMaterialType(vvv.material_type,'',2)}}<span class='copy-item'>{{vvv.material_name}}</span>&nbsp;&nbsp;
    {{# if(vvv.stock_m_type==1 && vvv.client_ordernum!=''){ }}
    <span class='copy-item'>B{{vvv.caigou_number}}</span>
    {{#  } }}
    <span class='copy-item'>{{vvv.client_ordernum}}</span>
    <br/>
    {{#  }); }}
</script>
<script type="text/html" id="caigounumberTpl">
    {{#  layui.each(d.detail, function(kkk, vvv){ }}
		{{# if(vvv.caigou_number!=''){ }}
			<span class='copy-item'>B{{vvv.caigou_number}}</span>
		{{#  } }}
		<br/>
    {{#  }); }}
</script>
<script type="text/html" id="factoryTpl">
    {{#  layui.each(d.detail, function(kkk, vvv){ }}
		{{# if(vvv.ft_name!='' && vvv.factory_id>0){ }}
			<span class='copy-item'>{{vvv.ft_name}}</span>
		{{#  } }}
		<br/>
    {{#  }); }}
</script>
<script type="text/html" id="checkinTypeTpl">
    {{#  layui.each(d.detail, function(kkk, vvv){ }}
		{{# if(vvv.stock_m_type==0){ }}常规料{{#  } }}
		{{# if(vvv.stock_m_type==1){ }}备料{{#  } }}
		{{# if(vvv.stock_m_type==2){ }}裁剪余料{{#  } }}
		入库
		<br/>
    {{#  }); }}
</script>
<script type="text/html" id="meterTpl">
    {{#  layui.each(d.detail, function(kkk, vvv){ }}
			<span class='copy-item'>{{vvv.use_num}}</span>
		<br/>
    {{#  }); }}
</script>


<script src="__PUBLIC_JS__/jquery.2.1.4.min.js?v={:config('hisiphp.version')}"></script>
<script src="__PUBLIC_JS__/xm-select/dist/xm-select.js?v={:config('hisiphp.version')}"></script>
<script src="__PUBLIC_JS__/vue@3.2.26/dist/vue.global.js"></script>
<script type="text/javascript">

    layui.use(['table', 'laydate', 'form', 'laytpl','tool','layer'], function() {
        var $ = layui.jquery;
        var table = layui.table;
        var laydate = layui.laydate;
        var form = layui.form;
        var layer = layui.layer;
        var initialize=0,second_initialize=0,first_init=0,changetab=0;
        laydate.render({
            elem: '#create_date_range'
            ,range: '~'
            ,theme: 'molv'
            ,mark: {'{:$today}':''}
            ,change: function(value, date, endDate){
                $('#create_date_range').val(value);
                $('#layui-laydate1').remove();//关闭面板
            }
        });
        laydate.render({
            elem: '#create_date_range1'
            ,range: '~'
            ,theme: 'molv'
            ,mark: {'{:$today}':''}
            ,change: function(value, date, endDate){
                $('#create_date_range1').val(value);
                $('#layui-laydate2').remove();//关闭面板
            }
        });

        laydate.render({
            elem: '#stall_order_time'
            ,range: '~'
            ,theme: 'molv'
            ,mark: {'{:$today}':''}
            ,change: function(value, date, endDate){
                $('#stall_order_time').val(value);
                $('#layui-laydate3').remove();//关闭面板
            }
        });
        window.status=0;
        window.statCli = function(status) {
            var url='{:url()}?status='+status;
            window.status=status;
            $("#hisi-table-search").attr('action',url);
            $("#seacher").click();
            changetab=1;
        }

        var opTable=table.render({
            elem: '#dataTable'
            ,url: '{:url("", ["status" => $status])}' //数据接口
            ,page: true //开启分页
            //,skin: 'row'
            ,even: true
            ,limit: 20
            ,limits: [20,50,100,150,200]
            ,text: {
                none : '暂无相关数据'
            }
            ,toolbar: '#toolbar'

            ,defaultToolbar: ['exports', 'print']
            ,cols: [[ //表头
                {type:'checkbox'}
				,{field: 'adminid_create_username', title: '发起人',width:150}
                ,{field: 'create_time', title: '发起时间',width:150}
                ,{field: 'material_name', title: '材料名称-订单号',width:200,templet:'#nameTpl'}
				,{field: 'factory_name', title: '工厂',width:110,templet:'#factoryTpl'}
                ,{field: '', title: '采购批号',width:60,templet:'#caigounumberTpl'}
                ,{field: 'remark', title: '入库类型',width:150,templet:'#checkinTypeTpl'}
				,{fiel: '', title: '入库米数',width:60,templet:'#meterTpl'}
				,{field: 'col4', title: '状态',width:60 ,templet:function(d){ return d.action_state=='110' ? '已入库' : '待入库';}}
                // ,{field: 'client_ordernum', title: '订单号/采购批号',width:60}
                // ,{field:'pic',title : '图片', templet:'#picTpl',width:110}
                // ,{field: '', title: '发起人',width:150}
                // ,{field: '', title: '发起时间',width:150}
                // ,{field: '', title: '材料名称/型号/色号/颜色',width:200}
                // ,{field: '', title: '物料SKU',width:60}
                 
                // ,{field: '', title: '入库类型',width:60}
                // ,{fieldd: '', title: '订单号/SKU/帐号',width:150}
                // ,{field: '', title: '工厂',width:100}
                // ,{fiel: '', title: '入库米数',width:60}
				//,{field: 'storehouse_name', title: '货仓',width:130}
                ,{field: 'col3', title: '操作',templet:'#buttonTpl',width:100}
            ]]
            ,done: function(res, curr, count){
                var data=res.data;
                var status=res.status;
                for (var i in data){
                    $('#stall-ids-'+data[i]['id']).val(data[i]['stall_id']);
                }
                layui.form.render();
                if(status==1){
                    $('table tr').each(function(i){
                        var remove_field=['time_payment'
                        ];
                        for(var i in remove_field) {
                            var temp=$(this).find('[data-field="'+remove_field[i]+'"]').remove();
                        }
                    });
                    $('.addStockOrder').show();
                    $('.stockActionReturn').remove();
                    $('.stockActionDetail').show();
                    $('.stockActionDetailSelect').remove();
                }else if(status==2){
                    $('table tr').each(function(i){
                        var remove_field=['time_submit','username'
                        ];
                        for(var i in remove_field) {
                            var temp=$(this).find('[data-field="'+remove_field[i]+'"]').remove();
                        }
                    });
                    $('.addStockOrder').remove();
                    $('.stockActionReturn').show();
                    $('.stockActionDetailSelect').show();
                    $('.stockActionDetail').remove();
                    // $('.bill-list-a').attr('href',$('.bill-list-a').attr('href')+'&status_real=0&status_type=1') ;
                }
                table.on('edit(demoEvent)', function(obj){
                    var value = obj.value //得到修改后的值
                        ,d = obj.data //得到所在行所有键值
                        ,field = obj.field; //得到字段
                    var id=d.id;

                    $.ajax({
                        type: "POST",
                        url: "{:url('editUnit')}",
                        data: "id="+d.id+"&field="+field+"&value="+value,
                        dataType:"json",
                        success: function(res){
                            if (res.code == 1) {
                                layer.msg(res.msg, {icon: 1});
                            } else {
                                layer.msg(res.msg, {icon: 2,anim: 6});
                            }
                        }
                    });
                });
            }
        });
		// 刷新当前页
		window.reloadTable = function () {
			var that = $("#hisi-table-search-optable"), 
	            arr = that.serializeArray(), 
	            where = new Array(),
	            dataTable = that.attr('data-table') ? that.attr('data-table') : 'dataTable',
	            currPage = $(".layui-laypage-em").next().html(),
	            options = new Function('return '+ that.attr('hisi-data'))() || {page: {curr:currPage}};
            for(var i in arr) {
                where[arr[i].name] = arr[i].value;
            }
        
	        options.url = that.attr('action');
	        options.where = where;
	        
	        opTable.reload(options);
	        return false;
		}
    });

</script>